package com.unittec.drainage.provider.auth.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.unittec.drainage.provider.auth.entity.SysUser;
import com.unittec.drainage.provider.auth.entity.SysUserDepart;
import com.unittec.drainage.provider.auth.mapper.SysUserDepartMapper;
import com.unittec.drainage.provider.root.ServiceRoot;

/**
 * @description 用户部门Service
 * @author Jason
 * @date 2019/11/07
 */
@Service
public class SysUserDepartService extends ServiceRoot<SysUserDepartMapper, SysUserDepart> {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 根据部门id查询用户列表
     *
     * @param depId
     * @return
     */
    public List<SysUser> queryUserByDepId(String depId) {
        LambdaQueryWrapper<SysUserDepart> queryUserDep = new LambdaQueryWrapper<SysUserDepart>();
        queryUserDep.eq(SysUserDepart::getDepId, depId);
        List<String> userIdList = new ArrayList<>();
        List<SysUserDepart> uDepList = this.list(queryUserDep);
        if (uDepList != null && uDepList.size() > 0) {
            for (SysUserDepart uDep : uDepList) {
                userIdList.add(uDep.getUserId());
            }
            List<SysUser> userList = sysUserService.listByIds(userIdList);
            for (SysUser sysUser : userList) {
                sysUser.setSalt("");
                sysUser.setPassword("");
            }
            return userList;
        }
        return new ArrayList<SysUser>();
    }




}
